import 'package:boss/color_constant.dart';
import 'package:boss/models/offers.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/shadow_radius_card.dart';
import 'package:hi_common/hi_common.dart';

import 'package:flutter/material.dart';

class OffersItem extends StatelessWidget {
  final Offers data;
  final VoidCallback onTap;

  const OffersItem({
    Key key,
    @required this.data,
    this.onTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.translucent,
      child: ShadowRadiusCard(
        margin: EdgeInsets.only(
          bottom: 30.w,
        ),
        padding: EdgeInsets.only(
          left: 40.w,
          right: 30.w,
          top: 40.w,
          bottom: 40.w,
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text(
                  data.activityName,
                  style: TextStyleConstant().normal_1_32,
                ),
                Container(
                  padding: EdgeInsets.symmetric(
                    horizontal: 13.w,
                    vertical: 2.w,
                  ),
                  decoration: BoxDecoration(
                    border: Border.all(
                      color: ColorConstant.fe7f76,
                      width: 1.px,
                    ),
                    borderRadius: BorderRadius.circular(
                      4.w,
                    ),
                  ),
                  child: Center(
                    child: Text(
                      data.discountTypeString,
                      style: TextStyleConstant().origin_28,
                    ),
                  ),
                ),
              ],
            ),
            _buildTime(),
          ],
        ),
      ),
    );
  }

  Widget _buildTime() {
    if (data.activityType == 0) {
      return Text(
        '持续有效',
        style: TextStyleConstant().normal_3_24,
      );
    } else {
      return Text('${StringUtil.line2Backslash(data.startDate)} - ${StringUtil.line2Backslash(data.endDate)}');
    }
  }
}
